package xyz.eden.boot.uc.adapter.api;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.eden.boot.uc.api.dto.res.UserBaseInfoResDTO;
import xyz.eden.boot.uc.api.feign.UserInfoFeignService;
import xyz.eden.boot.uc.application.config.ServerConfig;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * UserInfoFeignServiceImpl
 *
 * @author gavin
 * @version 1.0
 * @descriptor
 * @date 2023/7/30 13:00
 */
@Slf4j
@RestController
@RequestMapping(value = "feign/user")
public class UserInfoFeignServiceImpl implements UserInfoFeignService {

    @Resource
    private ServerConfig serverConfig;

    @Resource
    private HttpServletRequest request;

    @Override
    @GetMapping(value = "base/{id}")
    public UserBaseInfoResDTO getBaseInfo(@PathVariable(value = "id") Long userId) {
        String token = request.getHeader(HttpHeaders.AUTHORIZATION);
        String addToken = request.getHeader("token");
        log.info("UserInfoFeignServiceImpl.getBaseInfo - userId: [{}], token: [{}], addToken: [{}].", userId, token, addToken);
        return UserBaseInfoResDTO.builder()
                .id(userId).username("tom_" + userId + serverConfig.getServerPort()).age(RandomUtils.nextInt(1, 200))
                .build();
    }
}
